import java.util.HashMap;

import gui.Button;
import gui.GUI;
import gui.PColor;
import gui.PlayButton;
import gui.Plot;
import gui.Slider;

import processing.core.PApplet;
import OceanModel.OceanModel;
import OceanModel.Parameters;

public class JavaOceanModel extends PApplet {

	OceanModel model;
	Parameters inputParams = new Parameters();
	
	GUI gui;

	Plot plot;
	PColor pcolor;
	PlayButton playButton;
	Button newButton;
	Slider slider;
	
	//--------setup-----------

	public void setup() {
        // size always must be the first call to processing
		size(900, 600);
				
		HashMap<String, String> fonts = new HashMap<String, String>();
		fonts.put("small", "Futura-Medium-10.vlw");
		fonts.put("normal", "Futura-Medium-12.vlw");
		fonts.put("large", "Futura-Medium-18.vlw");
		fonts.put("max", "Futura-Medium-80.vlw");
		
        // Run the GUI setup
	    gui = new GUI(this, fonts, 200);
	    gui.setFont("normal");
      
        // Create Ocean Model
	    model = new OceanModel(inputParams);
	 
	    // Initialize GUI
	    double[] position =  {25., 25., 50., 50.};
	    playButton = gui.addPlayButton(position);

	    double[] position2 =  {200., 100., 400., 400.};
	    pcolor = gui.addPColor(position2, model.eta.getData()[0]);
	    pcolor.title("Sea Surface Height");
	    pcolor.xLabel("Distance");
	    pcolor.yLabel("Distance");
	    pcolor.colorbar();

	    double[] position3 =  {200., 25., 100., 20.};
	    slider = gui.addSlider(position3, (float)0., (float)100.);

	    double[] position4 =  {700., 100., 150., 400.};
	    plot = gui.addPlot(position4, model.eta.getData()[0][25], model.v.getData()[0][25]);
	    plot.title("Sea Surface Height");
	    plot.xLabel("eta");
	    plot.yLabel("v");
	    
	}

	//--------draw-----------

	public void draw() {
		
        // If the playButton has been pressed
		if ( playButton.isPlay() ) {
			
            // Only redraw the GUI every 10 model time steps
            for (int i=0; i < 10; i++) {
        		// Do the model logic
	            model.step();
            } 
            
    		// Update the data being plotted
            pcolor.updateData(model.eta.getData()[0]);
            plot.updateData(model.eta.getData()[0][25], model.v.getData()[0][25]);
            
		}
		
		// Update the GUI
		gui.draw();
	}	
	
	//--------GUI functions-----------
	
	public void mousePressed() {
		gui.mousePressed();
	}

	public void mouseClicked() {
		gui.mouseClicked();
	}

	public void mouseDragged() {
		gui.mouseDragged();
	}

	public void mouseMoved() {
		gui.mouseMoved();
	}

	public void mouseReleased() {
		gui.mouseReleased();
	}

	public void keyPressed() {
		gui.keyPressed();
	}
	
}